package cn.me.alphamq.nameserver.config;

import cn.me.alphamq.common.util.PropertiesUtil;

import java.util.Properties;

/**
 * nameserver 的配置类
 *
 * @author f
 */
public class NameServerProperties {

    /**
     * nameserver 的端口号
     */
    private final Integer nameServerPort;

    /**
     * 与 nameserver 建立连接时验证使用的用户名
     */
    private final String nameServerUsername;

    /**
     * 与 nameserver 建立连接时验证使用的密码
     */
    private final String nameServerPassword;

    public NameServerProperties(Integer nameServerPort, String nameServerUsername, String nameServerPassword) {
        this.nameServerPort = nameServerPort;
        this.nameServerUsername = nameServerUsername;
        this.nameServerPassword = nameServerPassword;
    }

    /**
     * 根据 properties 加载一个全局配置的对象
     *
     * @param properties 配置对象
     * @return 填充配置的对象
     */
    public static NameServerProperties load(Properties properties) {
        return new NameServerProperties(
                PropertiesUtil.getIntProperty(properties, "nameserver.port"),
                PropertiesUtil.getNotNullProperty(properties, "nameserver.username"),
                PropertiesUtil.getNotNullProperty(properties, "nameserver.password")
        );
    }

    public Integer getNameServerPort() {
        return nameServerPort;
    }

    public String getNameServerUsername() {
        return nameServerUsername;
    }

    public String getNameServerPassword() {
        return nameServerPassword;
    }
}
